package haxeframe.physics.fixtures;

import box2D.collision.shapes.B2PolygonShape;
import box2D.common.math.B2Vec2;

class FixtureBox extends Fixture
{
	public function new(xml:Xml, scale:Float, symbolScale:Float){
		super(xml, scale, symbolScale);
	}

	public function FixtureBox()
	{
	}
	
	public override function init():Void
	{
		super.init();

		var boxShape:B2PolygonShape = new B2PolygonShape();
		
		var boxX:Float = Std.parseFloat(_xml.get('x')) * _symbolScale/_scale;
		var boxY:Float = Std.parseFloat(_xml.get('y')) * _symbolScale/_scale;
		var boxWidth:Float = Std.parseFloat(_xml.get('width')) * 0.5 * _symbolScale/_scale;
		var boxHeight:Float = Std.parseFloat(_xml.get('height')) * 0.5 * _symbolScale/_scale;
		var boxRotation:Float = Std.parseFloat(_xml.get('rotation')) * Math.PI / 180;
		
		boxShape.setAsOrientedBox(boxWidth, boxHeight, new B2Vec2(boxX, boxY), boxRotation);
		
		definitions[0].shape = boxShape;
		
	}
}